package com.itheima;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
//时间的计算
public class LocalDatetimeDemo03 {
    public static void main(String[] args) {
        // 获取当前时间
        //2023-11-19T08:42:42.143
        LocalDateTime localDateTime = LocalDateTime.now();
        // 入参是long型，返回值类型是localdatetime
        // 当前时间+2年
        //2025-11-19T08:42:42.143
        LocalDateTime plusYears = localDateTime.plusYears(2L);
        // 当前月份+3个月
        //2024-02-19T08:42:42.143
        LocalDateTime plusMonths = localDateTime.plusMonths(3);
        // 当前时间-2天
        //2023-11-17T08:42:42.143
        LocalDateTime minusDays = localDateTime.minusDays(2);
        // 当前时间加1小时
        // 2023-11-19T09:42:42.143
        LocalDateTime plusHours = localDateTime.plusHours(1);
        // 当前时间-20分钟
        //2023-11-19T08:22:42.143
        LocalDateTime minusMinutes = localDateTime.minusMinutes(20);
        // 当前时间-45秒
        //2023-11-19T08:41:57.143
        LocalDateTime minusSeconds = localDateTime.minusSeconds(45);
        // 输出结果 "\n"作用是换行
        System.out.println("当前时间是：" + localDateTime + "\n" +
                "当前时间+2年后是：" + plusYears + "\n" +
                "当前月份+3个月是：" + plusMonths + "\n" +
                "当前时间-2天是：" + minusDays + "\n" +
                "当前时间+1小时数是：" + plusHours + "\n" +
                "当前时间是-20分钟是 ：" + minusMinutes + "\n" +
                "当前时间是-45秒是 ：" + minusSeconds + "\n");
    }
}
